#include<stdio.h>

int main(){
	int N,day,year,i,t,r,num_of_day;
	char month[10];
	char haab_months[19][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol",
								"chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};
	char tzolikn_dayname[20][10] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok",
									"chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
	scanf("%d",&N);
	printf("%d\n",N);
	while(N--){
		memset(month,0,sizeof(month));
		scanf("%d. %s %d",&day,month,&year);
		for(i=0;i<19;i++){
			if(!strcmp(month,haab_months[i]))
			    break;
  		}
		t = year*365 + i*20 + day + 1;
		r = t%260;
		t = t/260;
		if(r == 0){
			r = 260;
			t--;
		}
		num_of_day = (r%13 == 0 ? 13:r%13);
		printf("%d %s %d\n",num_of_day,&tzolikn_dayname[(r%20==0?20:r%20)-1][0],t);
	}
	return 0;
}
